
#ifndef __UTILS_H
#define __UTILS_H

#include  "Arduino.h"

//限制某个数的下界
template<typename T>
void limitLow(T &num, T limL)
{
    if (num < limL)
    {
        num = limL;
    }
}

//限制某个数的上界
template<typename T>
void limitHigh(T &num, T limH)
{
    if (num > limH)
    {
        num = limH;
    }
}


//限制某个数的上下界
template<typename T>
void limit(T &num, T limL, T limH)
{
    limitLow(num, limL);
    limitHigh(num, limH);
}


template <class T>
void swap(T *a, T *b)
{
    T temp;
    temp = *a;
    *a = *b;
    *b = temp;
}

String hex2str(uint8_t *buf, uint16_t len);
int str2hex(String str, unsigned char *output, int max_len);
bool stringToIPAddress(const String& ipString, IPAddress& ip);

#endif